package org.example.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @BelongsProject：blockchain-APTrace
 * @CreateTime 2024-06-12-11:42
 * @Author SweetPig
 */

public class OnlineUtil {


    public static Map<String, Object> online(RedisTemplate redisTemplate) {
        Set keys = redisTemplate.keys("online_user_*");
        List<Object> list = new ArrayList<>();
        for (Object key : keys) {
            Object o = redisTemplate.opsForValue().get(key);
            list.add(o);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("onlineList", list);
        //在线用户数量
        map.put("onlineNum", keys.size());
        return map;
    }
}
